from django.forms import ModelForm
from django.forms import widgets as wid
from . import models
from django.core.exceptions import ValidationError


class Anjian_li(ModelForm):
    class Meta:
        # fields = '__all__'
        exclude = ['aj_zhuangtai', 'aj_chufajine', 'aj_heiwodian', 'aj_wfss', 'aj_user', 'aj_time2', 'sb_time',
                   'xg_time']
        model = models.Anjian
    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)


class Anjian_jie(ModelForm):
    class Meta:
        exclude=['sb_time','xg_time',]
        model = models.Anjian

    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def clean_aj_juedingshu(self):
        juedingshu = self.cleaned_data.get("aj_juedingshu")
        zhuangtai = self.cleaned_data.get("aj_zhuangtai")
        if not juedingshu and zhuangtai not in ['3', '4']:
            raise ValidationError("这个字段是必填项。")
        return juedingshu

    def clean_aj_chufayiju(self):
        chufayiju = self.cleaned_data.get("aj_chufayiju")
        zhuangtai = self.cleaned_data.get("aj_zhuangtai")
        if not chufayiju and zhuangtai not in ['3', '4']:
            raise ValidationError("这个字段是必填项。")
        return chufayiju
